<style>
    .custom-toolbar{padding: 0em 1em 1em 0em;}
</style>
<div class="row-fluid clearfix">
    <div class="col-md-12 column">
        <ul class="breadcrumb">
            <li>
                <a href="index.html">首页</a>
            </li>
            <li class="active">
                商户跨行设置
            </li>
        </ul>
    </div>
    <div class="col-md-12 column">
        <div class="col-sm-12 div-page">
            <div class="col-sm-12 div-table">
                <div id="custom-toolbar" class="col-sm-12 custom-toolbar">
                    <button id="btn-DataConfirm" type="button" role="button" class="subFun btn btn-sm btn-Data btn-danger disabled"><span class="glyphicon glyphicon-check"></span> 审核</button>
                    <button id="btn-Filter" type="button" href="#modal-Filter" role="button" data-toggle="modal" class="btn btn-sm btn-primary pull-right" title="请选择数据">
                        <span class="glyphicon glyphicon-th-list"></span> 筛选</button>
                </div>
                <table id="table" class="table table-hover table-condensed" data-click-to-select="true"  data-single-select="true" data-height="430">
                    <thead>
                    <tr>
                        <th data-field="state" data-checkbox="true"></th>
                        <th data-field="merchno" data-halign="center" data-align="center" data-width="150">商户编号</th>
                        <th data-field="MerchantName" data-halign="center" data-align="center" data-width="120">商户名称</th>
                        <!--<th data-field="Name" data-halign="center" data-align="center" data-width="120">地区</th>-->
                        <th data-field="feeflag" data-halign="center" data-align="center" data-width="180"  data-formatter="feeflagStateFormatter">当前商户跨行设置</th>
                        <th data-field="verifyfeeflag" data-halign="center" data-align="center" data-width="180"  data-formatter="verifyfeeflagStateFormatter">目标商户跨行设置</th>
                        <th data-field="mccname" data-halign="center" data-align="center" data-sortable="true" data-width="420" data-formatter="MCCFormatter">MCC</th>
                        <th data-field="feetype" data-halign="center" data-align="center" data-sortable="true" data-width="110" data-formatter="feetypeStateFormatter">当前特殊计费</th>
                        <th data-field="verifyfeetype" data-halign="center" data-align="center" data-sortable="true" data-width="110" data-formatter="verifyfeetypeStateFormatter">目标特殊计费</th>
                        <th data-field="UseName" data-halign="center" data-align="center" data-width="120">客户姓名</th>
                        <th data-field="CertifiNo" data-halign="center" data-align="center" data-width="180">证件号码</th>
                    </tr>
                    </thead>
                </table>
            </div>
        </div>
        <div class="col-sm-12 alert alert-success div-alert" id="events-result" data-es="Aquí se muestra el resultado del evento"></div>
        <!-- #筛选条件遮罩层 --->
        <div class="modal fade" id="modal-Filter" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" data-backdrop="static">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                        <div class="modal-title" id="myModalLabel1">
                            筛选条件
                        </div>
                    </div>
                    <form id="queryForm" method="post" class="form-horizontal layer_msg">
                        <div class="modal-body">
                            <div class="form-group">
                                <label class="col-sm-3 control-label">证件类型</label>
                                <div class="col-sm-8">
                                    <select class="form-control" data-field="CertifiType" id="CertifiType" name="CertifiType" >
                                        <!--动态加载-->
                                    </select>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">证件号码</label>
                                <div class="col-sm-8">
                                    <input type="text" class="form-control" name="CertifiNo" id="CertifiNo"/>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">客户姓名</label>
                                <div class="col-sm-8">
                                    <input type="text" class="form-control" name="UseName" id="UseName"/>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">商户名称</label>
                                <div class="col-sm-8">
                                    <input type="text" class="form-control" name="MerchantName" id="MerchantName"/>
                                    <input type="hidden" name="IsCheck" value="01"/>
                                </div>
                            </div>
                        </div>
                        <div class="modal-footer">
                            <button id="modal-btn-query" type="submit" class="btn btn-primary" data-dismiss="modal">查询</button> <button id="modal-btn-close1" type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>

<script>
$(function () {

    /*BootstrapTable初始化-Start*/
    $('#table').bootstrapTable({
        queryParams:function(params) {
            var qp={
                page:params.offset/params.limit+1,
                rows:params.limit
            };
            return qp;
        },
        data:[],
        sidePagination: 'server',
        pagination:true,
        pageSize:10,
        search:false,
        responseHandler:function(data){
            return data.data;
        }
    })
        .on('click-row.bs.table', function (e, row, $element) {
            if ( $element.hasClass('selected') ) {
                $element.removeClass('info');
            }
            else {
                $element.parent('tbody').find(' > tr.selected ').removeClass("info");
                $element.addClass('info');
            }
        })
        .on('check.bs.table', function (e, row, $element) {
            $(".btn-Data").removeClass("disabled");
        })
        .on('uncheck.bs.table', function (e, row, $element) {
            $(".btn-Data").addClass("disabled");
        });
    /*BootstrapTable初始化-End*/

    /*筛选框查询按钮点击事件注册-Start*/
    FormatSelect(globalUrl+"api/Dict?Typeid=0000000005",$("#CertifiType"),"全部","",function(data){});
    $('#modal-Filter').modal('show');
    $("#btn-Filter").click(function(){
        $(".notice").css("color","#b2dba1");
    });
    $("#modal-btn-query").click(function(e){
        $(".btn-Data").addClass("disabled");
        $('#table').bootstrapTable('refresh',{url:globalUrl+"api/MerchantMcc?"+$("#queryForm").serialize()});
    });
    /*筛选框查询按钮点击事件注册-End*/

    /*子功能按钮事件注册-Start*/
    $('.subFun').on("click",function () {
        var fileName=$(this).attr("id").substr(8);
        var url="../assets/tpls/MerchantSet_"+fileName+".html";
        getTpls(url,function(resp){
            $("#modal-Template").html(resp);

            var selRowData=$('#table').bootstrapTable('getSelections')[0];
            /*FormatSelect(globalUrl+"api/Site?orgid=910",$("#area"),"请选择","",function(resp){});*/
            if(selRowData.merchtype==null)
            {
                selRowData.type="2";
                selRowData.merchtype="5998";
            }
            var type=selRowData.type;
            if(type!=null)
            {
                $("#MCCType").val(type);
                FormatSelect(globalUrl+"api/MerchantMcc?type="+type,$("#merchtype"),"请选择项目","",function(resp){});
            }
            //表格中选中行的数据绑定到当前功能模版
            dataBindToModal($('#validForm'),$('#table'));
            $("#merchtype").val(selRowData.merchtype);
            $("#area").val("3200");
            if($('#table').bootstrapTable('getSelections')[0].feeflag=="-")
            {
                $("#feeflag").val("-1");
            }
            switch (fileName){
                case "Confirm":
                    if((selRowData.verifyfeeflag==null|| $.trim(selRowData.verifyfeeflag)=="")&&(selRowData.verifyfeetype==null|| $.trim(selRowData.verifyfeetype)==""))
                    {
                        alert("此商户无需复核！");
                        return;
                    }
                    $("#feeflag").val(feeflagStateFormatter($('#table').bootstrapTable('getSelections')[0].feeflag,$('#table').bootstrapTable('getSelections')[0]));
                    $("#feetype").val(feetypeStateFormatter($('#table').bootstrapTable('getSelections')[0].feetype,$('#table').bootstrapTable('getSelections')[0]));
                    $("#verifyfeeflag").val(verifyfeeflagStateFormatter($('#table').bootstrapTable('getSelections')[0].verifyfeeflag,{}));
                    $("#verifyfeetype").val(verifyfeetypeStateFormatter($('#table').bootstrapTable('getSelections')[0].verifyfeetype,$('#table').bootstrapTable('getSelections')[0]));
                        $("#mccname").val($('#table').bootstrapTable('getSelections')[0].merchtype+" "+$('#table').bootstrapTable('getSelections')[0].mccname);
                    $('#validForm')
                            .formValidation({
                                err: {
                                    container: 'popover'
                                },
                                icon: {
                                    valid: 'glyphicon glyphicon-ok',
                                    invalid: 'glyphicon glyphicon-remove',
                                    validating: 'glyphicon glyphicon-refresh'
                                }
                            })
                            .on('success.form.fv', function(e) {
                                e.preventDefault({
                                    err: {
                                        container: 'popover'
                                    },
                                    icon: {
                                        valid: 'glyphicon glyphicon-ok',
                                        invalid: 'glyphicon glyphicon-remove',
                                        validating: 'glyphicon glyphicon-refresh'
                                    }
                                });
                                $.ajax({
                                    type: "get",
                                    url: globalUrl+"api/MerchantMcc?merchno="+$("#merchno").val()+"&ConfirmNoteSel="+$("#ConfirmNoteSel").val(),
                                    dataType: "json",
                                    success: function (resp) {
                                        if(resp.result)
                                        {
                                            $('#table').bootstrapTable('refresh',{url:globalUrl+"api/MerchantMcc?"+$("#queryForm").serialize()});
                                            $('#modal-Template').modal('hide');
                                        }
                                        else
                                        {
                                            alert(resp.msg);
                                        }
                                    },
                                    error:function(){
                                        alert("更新数据失败！");
                                    }
                                });
                            });
                    break;
                default:
            }
            $('#modal-Template').modal('show');
        });
    });
    /*子功能按钮事件注册-End*/
});
function feeflagStateFormatter(value, row) {
    var v='资金次日可用|正常收费';
    if(value=="1"){
        v='资金次日可用|免费';
    }
    if(value=="3"){
        v='资金实时可用|正常收费';
    }
    if(value=="4"){
        v='资金实时可用|免费';
    }
    return v;
};
function verifyfeeflagStateFormatter(value, row) {
    if(value!=null&&$.trim(value)!="")
    {
        value=value.substr(0,1);
    }
    else
    {
        return null;
    }
    var v='资金次日可用|正常收费';
    if(value=="1"){
        v='资金次日可用|免费';
    }
    if(value=="3"){
        v='资金实时可用|正常收费';
    }
    if(value=="4"){
        v='资金实时可用|免费';
    }
    return v;
};
function feetypeStateFormatter(value, row) {
    value+=row.feelevel;
    var v='无特殊计费';
    if(value=="040"){
        v='普通县乡优惠';
    }
    if(value=="041"){
        v='三农优惠';
    }
    return v;
}
function verifyfeetypeStateFormatter(value, row) {
    if(value!=null&&$.trim(value)!="")
    {
        value+=row.verifyfeelevel;
    }
    else
    {
        return null;
    }
    var v='无特殊计费';
    if(value=="040"){
        v='普通县乡优惠';
    }
    if(value=="041"){
        v='三农优惠';
    }
    return v;
}
function MCCFormatter(value, row) {
    if(row.merchtype!=null)
    {
        return row.merchtype+" "+row.mccname;
    }
    else
    {
        //return null;
        return "5998 无特殊计费";
    }
}
</script>